home *** CD-ROM | disk | FTP | other *** search
/ PC Format (UK) 188 / 01-04 PC Format 188 [2006-06] DVD side 1_.iso / DiscContents / Workshops / Workshops_Games / Sphere / InstallSphere1.0.exe / games / fg-demo / scripts / Game.js < prev    next >
Text File  |  2003-02-18  |  10KB  |  390 lines

  1. EvaluateSystemScript("clock.js");
  2. EvaluateSystemScript("timed_animation.js");
  3.  
  4. // This is the main game file. All of the player's data is stored here.
  5. function GameData()
  6. {
  7.     var t = new Object();
  8.     t.money = 0;                        // Current amount of money held by the party
  9.     t.clock = new Clock()            // Game clock
  10.     t.party = new Array();            // Characters that have joined
  11.     t.psize = 1;                            // Current size of party
  12.     t.events = Events();                // Events that have happened in the game
  13.     t.idolix = new Array();            // Idolix party has found
  14.     t.menuopen = false;                // Is there a menu open?
  15.     t.currentmenu;                    // Menu that is open
  16.     t.curBattle = undefined;        // Current battle
  17.     t.battleopen = false;                // Is battle open?
  18.     t.messageopen = false;            // Is there a message open
  19.     t.submenu = new Menu(true);
  20.     t.submenu.addItem("Inventory");
  21.     t.submenu.addItem("Ability");
  22.     t.submenu.addItem("Equipment");
  23.     t.submenu.addItem("Status");
  24.     t.submenu.addItem("Idolix");
  25.     t.submenu.addItem("Customize");
  26.     t.submenu.addItem("Tutorial");
  27.     t.submenu.addItem("Save/Load");
  28.     t.submenu.addItem("Exit Game");
  29.     t.submenu.returnSelection = true;
  30.     t.submenu.indent = 6;
  31.     t.sound = undefined;
  32.     t.messagex = 0;                    // Open message's x value
  33.     t.messagey = 0;                    // Open message's y value
  34.     t.messagew = 0;                    // Open message's w value
  35.     t.messagespeaker = "";            // Open message's speaker
  36.     t.messagetext = "";                // Open message's text
  37.     t.messageletter = 0;                // Open message's current letter
  38.     t.messagetime = 0;                // Time until message disappears
  39.     t.items = new Array();            // Items held by the party
  40.     // The following will be placed into the game's config.dat and save file
  41.     t.atb = "Wait";
  42.     t.accept = KEY_A;                // Accept key
  43.     t.cancel = KEY_SPACE;            // Cancel key
  44.     t.menu = KEY_F;                    // Menu key
  45.     t.start = KEY_SHIFT;            // Start key (pausing and stuff)
  46.     t.saveable = false;                // Is it possible to save
  47.     t.freeze = false;                    // Are the controls frozen
  48.     t.area = false;                        // Is there a submap warp here
  49.     t.areax = 0;                        // x coordinate of ShowArea()
  50.     t.areay = 0;                        // y coordinate of ShowArea()
  51.     t.areatext = "";                    // Name of current area
  52.     t.areamap = "";                    // Name of current map
  53.     t.location = "";                        // Name of location
  54.     t.menu_move = LoadSound("Cursor-move.wav");
  55.     t.menu_cancel = LoadSound("Cursor-cancel.wav");
  56.     t.menu_delay = 100;                // Delay for menu control
  57.     t.last_push = 0;                    // Last time a key was pressed
  58.     return t;
  59. }
  60.  
  61. function FillIn()
  62. {
  63.     Game.submenu.doWhile = InfoWindow;
  64.     Damizean.bMenu.items[0] = Commands.TAttack;
  65.     Damizean.bMenu.items[1] = Commands.TBlackMag;
  66.     Damizean.bMenu.items[2] = Commands.TSkill;
  67.     Damizean.bMenu.items[3] = Commands.TItem;
  68.     Damizean.commands[0] = Commands.TBlackMag;
  69.     Damizean.commands[1] = Commands.TSkill;
  70.     Damizean.commands[2] = Commands.TMess;
  71.     Damizean.commands[3] = Commands.TItem;
  72.     Damizean.bMenu.items[1].enabled = false;
  73.     Damizean.bMenu.items[2].enabled = false;
  74.     Damizean.bMenu.items[3].enabled = false;
  75.     Annika.position = "Back";
  76.     SetTalkActivationKey(Game.accept);
  77.     SetTalkDistance(5);
  78.     Game.items[0] = Items.Weapons[1].clone();
  79.     Game.items[1] = Items.Weapons[2].clone();
  80.     Enemies.Jude.item = Items.Weapons[1].clone();
  81. }
  82.  
  83. // This warps the player to another map
  84. function Warp(amap)
  85. {
  86.     ChangeMap(amap);
  87. }
  88.  
  89. // Moves entities easily
  90. function Move(person, direction, tiles)
  91. {
  92.     switch (direction)
  93.     {
  94.         case "east":
  95.             QueuePersonCommand(person, COMMAND_FACE_EAST, true);
  96.             for (var i = 0; i < tiles * 16; i ++)
  97.             {
  98.                 QueuePersonCommand(person, COMMAND_MOVE_EAST, false);
  99.             }
  100.             break;
  101.         case "west":
  102.             QueuePersonCommand(person, COMMAND_FACE_WEST, true);
  103.             for (var i = 0; i < tiles * 16; i ++)
  104.             {
  105.                 QueuePersonCommand(person, COMMAND_MOVE_WEST, false);
  106.             }
  107.             break;
  108.         case "south":
  109.             QueuePersonCommand(person, COMMAND_FACE_SOUTH, true);
  110.             for (var i = 0; i < tiles * 16; i ++)
  111.             {
  112.                 QueuePersonCommand(person, COMMAND_MOVE_SOUTH, false);
  113.             }
  114.             break;
  115.         case "north":
  116.             QueuePersonCommand(person, COMMAND_FACE_NORTH, true);
  117.             for (var i = 0; i < tiles * 16; i ++)
  118.             {
  119.                 QueuePersonCommand(person, COMMAND_MOVE_NORTH, false);
  120.             }
  121.             break;
  122.     }
  123. }
  124.  
  125. // Makes the person wait
  126. function Wait(person, seconds)
  127. {
  128.     for (var i = 0; i < seconds * 10; i ++)
  129.     {
  130.         QueuePersonCommand(person, COMMAND_WAIT, false);
  131.     }
  132. }
  133.  
  134. // Makes the person face the player
  135. function FacePlayer(person)
  136. {
  137.  
  138. }
  139.  
  140. // Random movement generator
  141. function MoveRandomly(person, speed)
  142. {
  143.     if (Game.personTalking != person)
  144.     {
  145.         var direction = Math.floor(Math.random() * (6 + speed));
  146.         var tiles = Math.floor(Math.random() * 2);
  147.         switch (direction)
  148.         {
  149.             default:
  150.                 Wait(person, tiles * speed);
  151.                 break;
  152.             case 1 + speed:
  153.                 Move(person, "north", tiles);
  154.                 break;
  155.             case 2 + speed:
  156.                 Move(person, "south", tiles);
  157.                 break;
  158.             case 3 + speed:
  159.                 Move(person, "east", tiles);
  160.                 break;
  161.             case 4 + speed:
  162.                 Move(person, "west", tiles);
  163.                 break;
  164.         }
  165.     }
  166. }
  167.  
  168. // Returns true or false if the event is on or off, depending on how it is used
  169. function IsEvent(eventNum, onoff)
  170. {
  171.     if (Game.events[eventNum] == onoff)
  172.     {
  173.         return true;
  174.     }
  175.     else
  176.         return false;
  177. }
  178.  
  179. // This does all the spiffy intro stuff
  180. function Introduction(fade_speed)
  181. {
  182.     this.events = new Array();
  183.     this.bg = Colors.Black;
  184.     this.current_event = 0;
  185.     this.current_process = "FadeFrom";
  186.     this.pressed = false;
  187.     this.timer = 0;
  188.     this.step = 255;
  189.     this.fade_speed = fade_speed;
  190.     this.music = false;
  191. }
  192.  
  193. // Add a new event to the intro scene
  194. Introduction.prototype.addEvent = function(type, file, wait)
  195. {
  196.     var event = new Object();
  197.     event.type = type;
  198.     if (type == "Image")
  199.     {
  200.         event.file = LoadImage(file);
  201.     }
  202.     if (type == "Text")
  203.     {
  204.         event.file = file;
  205.     }
  206.     if (type == "Animation")
  207.     {
  208.         event.file = new TimedAnimation(LoadAnimation(file));
  209.     }
  210.     event.wait = wait;
  211.     this.events[this.events.length] = event;
  212. }
  213.  
  214. // Play the intro scene
  215. Introduction.prototype.play = function()
  216. {
  217.     var playing = true;
  218.     if (this.music != false)
  219.     {
  220.         this.music.play(true);
  221.     }
  222.     while (playing)
  223.     {
  224.         ApplyColorMask(this.bg);
  225.         if (this.events[this.current_event] != undefined)
  226.         {
  227.             if (this.events[this.current_event].type == "Image")
  228.             {
  229.                 this.events[this.current_event].file.blit(GetScreenWidth() / 2 - (this.events[this.current_event].file.width / 2), GetScreenHeight() / 2 - (this.events[this.current_event].file.height / 2));
  230.             }
  231.             if (this.events[this.current_event].type == "Text")
  232.             {
  233.                 font.title.drawText(GetScreenWidth() / 2 - (font.title.getStringWidth(this.events[this.current_event].file) / 2), GetScreenHeight() / 2 - 9, this.events[this.current_event].file);
  234.             }
  235.             if (this.events[this.current_event].type == "Animation")
  236.             {
  237.                 this.events[this.current_event].file.blit(GetScreenWidth() / 2 - (this.events[this.current_event].file.animation.getWidth() / 2), GetScreenHeight() / 2 - (this.events[this.current_event].file.animation.getHeight() / 2));
  238.             }
  239.         }
  240.         // Fade from
  241.         if (this.current_process == "FadeFrom")
  242.         {
  243.             Fade(this.step, Colors.Black);
  244.             this.step -= this.fade_speed;
  245.             if (this.step < 0)
  246.             {
  247.                 this.current_process = "Wait";
  248.                 this.timer = GetTime();
  249.             }
  250.         }
  251.         if (this.current_process == "Wait")
  252.         {
  253.             if (this.timer + this.events[this.current_event].wait <= GetTime())
  254.             {
  255.                 this.current_process = "FadeTo";
  256.             }
  257.         }
  258.         // Fade to
  259.         if (this.current_process == "FadeTo")
  260.         {
  261.             Fade(this.step, Colors.Black);
  262.             this.step += this.fade_speed;
  263.             if (this.step > 255)
  264.             {
  265.                 if (this.pressed == false)
  266.                 {
  267.                     this.current_event ++;
  268.                     this.current_process = "FadeFrom";
  269.                 }
  270.                 if (this.pressed == true)
  271.                 {
  272.                     playing = false;
  273.                 }
  274.             }
  275.         }
  276.         FlipScreen();
  277.         if (this.events[this.current_event] == undefined)
  278.         {
  279.             playing = false;
  280.         }
  281.         if (IsKeyPressed(KEY_ENTER))
  282.         {
  283.             this.current_process = "FadeTo";
  284.             this.pressed = true;
  285.         }
  286.     }
  287.     if (this.music != false)
  288.     {
  289.         this.music.stop();
  290.     }
  291. }
  292.  
  293. function LastPush()
  294. {
  295.     if (Game.menu_delay + Game.last_push < GetTime())
  296.     {
  297.         return true;
  298.     }
  299.     else
  300.         return false;
  301. }
  302.  
  303. function KeyPressed(other)
  304. {
  305.     Game.last_push = GetTime();
  306.     if (other != undefined)
  307.     {
  308.         Game.sound = Game.menu_cancel;
  309.         Game.soundTime = GetTime();
  310.         Game.sound.play(false);
  311.     }
  312.     else
  313.     {
  314.         Game.sound = Game.menu_move;
  315.         Game.soundTime = GetTime();
  316.         Game.sound.play(false);
  317.     }
  318. }
  319.  
  320. function Fade(step, color)
  321. {
  322.     ApplyColorMask(CreateColor(color.red, color.green, color.blue, step));
  323. }
  324.  
  325. // This will return the correct radians from degrees
  326. function DtR(degree)
  327. {
  328.     if (degree >= 0)
  329.         return Math.PI * degree / 180;
  330.     if (degree < 0)
  331.         return Math.PI * (360 + degree) / 180;
  332. }
  333.  
  334. function GetPartySize()
  335. {
  336.     var psize = Game.party.length;
  337.     if (Game.party.length > 3)
  338.     {
  339.         psize = 3;
  340.     }
  341.     return psize;
  342. }
  343.  
  344. function QuitMessage(message, heading)
  345. {
  346.     if (heading == undefined)
  347.     {
  348.         heading = "ERROR";
  349.     }
  350.     var sphere = LoadImage("Sphere.png");
  351.     while (!IsKeyPressed(KEY_SHIFT))
  352.     {
  353.         sphere.blit(160 - sphere.width / 2, 120 - sphere.height / 2);
  354.         font.title.drawText(160 - font.title.getStringWidth(heading) / 2, 40, heading);
  355.         font.drawTextBox(40, 140, 240, 60, message);
  356.         FlipScreen();
  357.     }
  358.     Exit();
  359. }
  360.  
  361. function AilmentArray()
  362. {
  363.     var ailments = new Array();
  364.     ailments[0] = false; // Poison
  365.     ailments[1] = false; // Mute
  366.     return ailments;
  367. }
  368.  
  369. function ElementArray()
  370. {
  371.     var elements = new Array(8);
  372.     elements[0] = 100; // Fire
  373.     elements[1] = 100; // Ice
  374.     elements[2] = 100; // Lightning
  375.     elements[3] = 100; // Water
  376.     elements[4] = 100; // Wind
  377.     elements[5] = 100; // Earth
  378.     elements[6] = 100; // Holy
  379.     elements[7] = 100; // Shadow
  380.     return elements;
  381. }
  382.  
  383. function Interrupt()
  384. {
  385.     if (Game.sound != undefined && Game.soundTime + 310 <= GetTime())
  386.     {
  387.         Game.sound.stop();
  388.         Game.sound = undefined;
  389.     }
  390. }